package com.zzyl.controller;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.utils.ObjectUtil;
import com.zzyl.vo.NursingProjectPageVo;
import com.zzyl.vo.VisitVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ffk
 * @date 2024/5/9 15:50
 */


@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理") // 添加Swagger注解，指定API标签为"护理项目管理"
@Slf4j
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页查询护理项目信息
     */
    @GetMapping
    @ApiOperation("分页查询护理项目信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "5", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "项目名称", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "项目状态", dataType = "int", paramType = "query")
    })
    public ResponseResult<PageResponse<NursingProjectPageVo>> queryByPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer status) {
        log.info("护理项目分页请求信息：{}，{}，{}，{}", pageNum, pageSize, name, status);
        PageResponse<NursingProjectPageVo> byPage = nursingProjectService.findByPage(pageNum, pageSize, name, status);
        return ResponseResult.success(byPage);
    }

    @PostMapping
    @ApiOperation("添加护理项目")
    public ResponseResult addProject(@RequestBody NursingProjectDto nursingProjectDto) {
        log.info("添加护理项目请求信息：{}", nursingProjectDto);
        nursingProjectService.addOneProject(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询护理项目信息")
    @ApiImplicitParam(name = "id", value = "项目ID", required = true, dataType = "Long", paramType = "path")
    public ResponseResult<NursingProjectPageVo> queryById(@PathVariable Long id) {
        log.info("根据id查询信息，请求的id为：{}", id);
        NursingProjectPageVo nursingProjectPageVo = nursingProjectService.queryOneById(id);
        log.info("根据id查询信息，查询到的信息为：{}", nursingProjectPageVo);
        return success(nursingProjectPageVo);
    }

    @PutMapping
    @ApiOperation("修改护理项目信息")
    public ResponseResult<NursingProjectPageVo> updateProject(@RequestBody NursingProjectDto nursingProjectDto) {
        log.info("修改护理项目的请求信息：{}", nursingProjectDto);
        nursingProjectService.updateOneProject(nursingProjectDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据ID删除护理项目信息")
    @ApiImplicitParam(name = "id", value = "项目ID", required = true, dataType = "Long", paramType = "path")
    public ResponseResult deleteProject(@PathVariable Long id) {
        log.info("根据id删除护理项目，请求的id为：{}", id);
        nursingProjectService.deleteOneProject(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理项目状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "项目ID", required = true, dataType = "Long", paramType = "path"),
            @ApiImplicitParam(name = "status", value = "项目状态", required = true, dataType = "int", paramType = "path")
    })
    public ResponseResult updateProjectStatus(@PathVariable(value = "id") Long id, @PathVariable(value = "status") Integer status) {
        log.info("修改护理项目状态，请求的id为：{}，状态为：{}", id, status);
        nursingProjectService.updateProjectStatus(id, status);
        return success();
    }

}
